home *** CD-ROM | disk | FTP | other *** search
/ Deutsche Edition 2 / Deutsche Edition 2.iso / mac / PROGRAMME / ARTAbrot 1.1 ƒ / MBROT.S < prev    next >
Encoding:
Text File  |  1993-11-22  |  6.4 KB  |  196 lines  |  [TEXT/MPS ]

  1. /************************************************************************/
  2. /*                                                                        */
  3. /*    FILE:    MBROT.S -- MANDELBROT DSP3210 PROGRAM                        */
  4. /*                                                                        */
  5. /*    PURPOSE:    DSP3210 routines to generate Mandelbrot image data.        */
  6. /*                                                                        */
  7. /*    AUTHOR:    George T. Warner                                            */
  8. /*                                                                        */
  9. /*    NOTES:    Variables at param block must be initialized                */
  10. /*            before setting Startflag to allow the program to run.  The    */
  11. /*            results are stored in RAM starting at address OutputData.    */
  12. /*            Program completes by writing a nonzero value to Doneflag.    */
  13. /*                                                                        */
  14. /*    REVISIONS:                                                            */
  15. /*    10/22/93    GTW    Increased maximum line length to 1280 pixels.        */
  16. /*    08/22/93    GTW    Converted from VCOS to ARTA code.                    */
  17. /*    02/14/92    GTW    Cleaned up.                                            */
  18. /*    12/23/91    GTW    First working DSP3210 version.                        */
  19. /*                                                                        */
  20. /************************************************************************/
  21.  
  22. #include "DSP3210.h"
  23.  
  24. /* Macro for PC relative addressing. */
  25. #define AddressPR(LAB) pc + LAB - (.+8)
  26.  
  27. NewModule(MBrot, kdspSmoothModule, kdspAutoCache, cmain)
  28.     long    100, 4, 655        /* I don't know about this. */
  29.  
  30. NewCachedProgramSection(cmain, MBrot)
  31. NewParameterSection(brobuf, kdspAppSpecificData, MBrot)
  32.  
  33. AppendSection(cmain)
  34.     *sp++ = r5
  35.     *sp++ = r6
  36.     *sp++ = r8
  37.     *sp++ = r10
  38.     *sp++ = r11
  39.     *sp++ = r13
  40.     *sp++ = r14
  41.     *sp++ = r18                    /* Push r18 onto stack. */
  42.  
  43.     GetSectionAddress(r5, brobuf)    /* Get address for brobuf and put in r5.    */
  44.     /* Once I get the section base address in a register (r5), I can make all    */
  45.     /* future accesses by register relative addressing.                            */
  46.  
  47.     r2 = r5 + (Inited - Startflag)        // r2 = Inited
  48.  
  49.     r1 = *r2
  50.     nop
  51.     if(ne) pcgoto Wait_for_go    /* Go ahead if initialized. */
  52.     r1 = (short) 1
  53.  
  54.     r3 = r5 + (Startflag - Startflag)        // r3 = Startflag
  55.     *r3 = r0                    /* Clear startflag. */
  56.     r4 = r5 + (Doneflag - Startflag)        // r4 = Doneflag
  57.     *r4 = r0                    /* Clear doneflag. */
  58.     *r2 = r1                    /* Set inited flag. */
  59.  
  60. Wait_for_go:
  61.     r4 = r5 + (Startflag - Startflag)        // r4 = Startflag
  62.     r3 = *r4
  63.     nop
  64.     if(eq) pcgoto exit            /* Be a "good citizen" and return. */
  65.     nop
  66.  
  67.     *r4 = r0                    /* Clear Startflag. */
  68.  
  69.     r13 = r0                    /* Zero point counter. */
  70.     r10 = r5 + (OutputData - Startflag)        // r10 = OutputData            /* Set pointer to output data. */
  71.     r14 = r5 + (Maxiter - Startflag)        // r14 = Maxiter
  72.     r14 = *r14                    /* Get the maximum number of iterations. */
  73.     r8 = AddressPR(Scrfl)                    /* Set pointer to temp storage. */
  74.     
  75.     r2 = r5 + (Xstart - Startflag)        // r2 = Xstart                    /* Convert IEEE format. */
  76.     r3 = AddressPR(myXstart)
  77.     /* Use these to convert from IEEE to DSP3210 format. */
  78.     *r3++ = a0 = dsp(*r2++)
  79.     *r3++ = a0 = dsp(*r2++)
  80.     *r3 = a0 = dsp(*r2)
  81.                                 /* Compute y coordinate. */
  82.     /* r11 - iteration count. */
  83.     /* r13 - point counter. */
  84.     /* r14 - max iterations. */
  85.     /* r8  - pointer to temp storage. */
  86. Mloop:
  87.     r2 = AddressPR(Scrlong)        /* Set pointer to temp storage. */
  88.     *r2 = r13                    /* Store in memory. */
  89.     r3 = AddressPR(myDelta)        /* Set pointer to delta x. */
  90.     a0 = float32(*r2)            /* Convert count to floating point. */
  91.     r6 = AddressPR(myXstart)    /* Set pointer to base x. */
  92.     r11 = AddressPR(Zero)
  93.     a2 = *r6 + a0 * *r3            /* Coordinate=base+(pointnum * deltaX) */
  94.     r3 = AddressPR(myYstart)
  95.     a3 = *r3                    /* Get imaginary cooridinate (y). */
  96.     a0 = *r11                    /* Zero the accumulator. */
  97.     a1 = *r11                    /* Zero the accumulator. */
  98.     *r8++ = a2 = a2                /* Save real c. */
  99.     *r8-- = a3 = a3                /* Save imaginary c. */
  100.     r11 = r0                    /* Zero iteration count. */
  101.  
  102. Mandel: 
  103.     pccall TestMag(r18)
  104.     r11 = r11 + 1                /* Increment iteration count. */
  105.  
  106.     if(ne) pcgoto Pointdone        /* This point diverged; it's done. */
  107.     nop
  108.  
  109.     r11 - r14                    /* Compare to max. num. of iterations. */
  110.     if(ge) pcgoto Pointdone        /* Return if greater than or equal to. */
  111.     nop
  112.  
  113.  
  114.     /* Now the famous z = z^2 + C function */
  115. DoTheBrot:
  116.     a2 = a0 * a1
  117.     a3 = a0 * a0
  118.     a0 = a3 - a1 * a1            /* This gives the real part of z squared. */
  119.     a1 = a2 + a2                /* This gives the imaginary part of z squared. */
  120.     a0 = a0 + *r8++                /* This is the +C (real) part of the equation. */
  121.     pcgoto Mandel
  122.     a1 = a1 + *r8--                /* This is the +C (img.) part of the equation. */
  123.  
  124. Pointdone:
  125.     *r10++ = (short)r11            /* Save result. */
  126.     r2 = r5 + (Points - Startflag)        // r2 = Points
  127.     r2 = *r2                    /* Get the number of points to do. */
  128.     r13 = r13 + 1
  129.     r2 - r13                    /* Are there more points to do? */
  130.     if(gt) pcgoto Mloop            /* If so, go do next point. */
  131.     nop 
  132.  
  133. Linedone:
  134.     r14 = (short)0x69            /* Just an arbitrary non-zero number. */
  135.     r4 = r5 + (Doneflag - Startflag)    // r4 = Doneflag
  136.     *r4 = r14                    /* Indicate that DSP is done. */
  137.  
  138. exit:
  139.     r4 = sp - 4
  140.     r18 = *r4--                    /* Pull r18 off stack. */
  141.     r14 = *r4--                    /* Pull r14 off stack. */
  142.     r13 = *r4--                    /* Pull r13 off stack. */
  143.     r11 = *r4--                    /* Pull r11 off stack. */
  144.     r10 = *r4--                    /* Pull r10 off stack. */
  145.     r8 = *r4--                    /* Pull r8 off stack. */
  146.     r6 = *r4--                    /* Pull r6 off stack. */
  147.     r5 = *r4--                    /* Pull r5 off stack. */
  148.     sp = sp - 32                /* Restore stack pointer. */
  149.     return(r18)
  150.     nop
  151.  
  152. /************************************************************************/
  153. /* TestMag -- subroutine to compare magnitude of complex number in a0    */
  154. /*        and a1 to 2.0.  If greater, r1 = 1 upon exiting; if                */
  155. /*        less, r1 = 0.                                                    */
  156. /************************************************************************/
  157. TestMag:
  158.     a3 = a0 * a0                /* Square real part. */
  159.     a3 = a3 + a1 * a1            /* Add to img. part squared. */
  160.     r2 = AddressPR(Four)
  161.     a3 = a3 - *r2                /* Compare to 4.0. */
  162.     nop
  163.     nop
  164.     nop
  165.     if(alt) pcgoto Donef        /* If negative result, goto Done. */
  166.     r1 = r0
  167.     r1 = (short)1                /* Result did not diverge. */
  168. Donef:
  169.     return(r18)
  170.     r1 - 0                        /* Set flags based on result. */
  171.  
  172. Four:        float 4.0            /* Number for magnitude comparisons. */
  173. Zero:        float 0.0
  174. Scrfl:        2 * float            /* Scratch pad. */
  175. Scrlong:    long                /* Scratch pad. */
  176. myXstart:    float    0.0
  177. myDelta:    float    0.0
  178. myYstart:    float    0.0
  179.  
  180.  
  181. AppendSection(brobuf)
  182. /* Note: Xstart, Delta, and Ystart all hold IEEE representations of    */
  183. /* floating point values.  Hence, they have been declared as longs    */
  184. /* in order that they not be confused with DSP floats.                */
  185.  
  186. Startflag:    int        0
  187. Doneflag:    int        0
  188. Points:        long    640        /* Number of points. */
  189. Maxiter:    long    63        /* Maximum number of iterations. */
  190. Xstart:        long    80        /* Starting real (x) coordinate. */
  191. Delta:        long    80        /* Delta x. */
  192. Ystart:        long    80        /* y coordinate. */
  193. Inited:        long    0        /* Initialization flag. */
  194. OutputData:
  195.             1280 * short
  196.